package com.inventive.jmscache.server;

import javax.jms.*;

/**
 * @author Grant Little <grant.little@coreservices.com.au>
 */
public class JmsCacheQueueSession extends JmsCacheSession implements QueueSession {

    protected boolean transactional = true;
    protected AcknowledgeMode acknowledgeMode = AcknowledgeMode.SESSION_TRANSACTED;

    public JmsCacheQueueSession(JmsCacheServer jmsCacheServer, boolean transactional, int acknowledgmentMode) {
        super(jmsCacheServer);
        this.transactional = transactional;
        if (!transactional) {
            this.acknowledgeMode = AcknowledgeMode.values()[acknowledgmentMode];
        } else {
            this.acknowledgeMode = AcknowledgeMode.SESSION_TRANSACTED;
        }
    }


    public QueueReceiver createReceiver(Queue queue) throws JMSException {
        return new JmsCacheQueueReceiver(this, (JmsCacheDestination)queue, acknowledgeMode);
    }

    public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException {
        return new JmsCacheQueueReceiver(this, (JmsCacheDestination)queue, messageSelector, acknowledgeMode, false);
    }

    public QueueSender createSender(Queue queue) throws JMSException {
        return new JmsCacheQueueSender(this, (JmsCacheDestination)queue);
    }
}
